//
//  WMBottomViw.m
//  Mink
//
//  Created by 周述坚 on 17/6/22.
//  Copyright © 2017年 周述坚. All rights reserved.
//

#import "WMBottomView.h"


@implementation WMBottomView{

    
    UIButton *cameraBut;
    UIButton *videoBut;
    UIButton *liveBut;
    UIButton *palyBut;
    UIButton *paiBut;
    UIButton *filterBut;
    UIButton *setBut;
    
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
        [self addMasConstraint];
        
    }
    return self;
}

- (void)setupUI{
    
    // 照相机
    cameraBut = [UIButton sj_buttonWithTitle:nil image:[UIImage imageNamed:@"ic_camera_i"] andHighLight:nil selectedImage:[UIImage imageNamed:@"ic_camera_n"]];
    cameraBut.selected = YES;
    cameraBut.tag = 1;
    [cameraBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    // 摄影
    videoBut = [UIButton sj_buttonWithTitle:nil image:[UIImage imageNamed:@"ic_video_i"] andHighLight:[UIImage imageNamed:@"ic_video_n"] selectedImage:[UIImage imageNamed:@"ic_video_n"]];
    videoBut.tag = 2;
    [videoBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    // 直播按钮
    liveBut = [UIButton sj_buttonWithTitle:nil image:[UIImage imageNamed:@"ic_live_i"] andHighLight:[UIImage imageNamed:@"ic_live_n"] selectedImage:[UIImage imageNamed:@"ic_live_n"]];
    liveBut.tag = 3;
    [liveBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    // 播放按钮
    palyBut = [UIButton sj_buttonWithTitle:nil image:[UIImage imageNamed:@"ic_camera_i"] andHighLight:[UIImage imageNamed:@"ic_camera_n"] selectedImage:[UIImage imageNamed:@"ic_camera_n"]];
    palyBut.tag = 4;
    [palyBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 拍照按钮
    paiBut = [UIButton sj_buttonWithTitle:nil image:[UIImage imageNamed:@"ic_camera_unavailable"] andHighLight:[UIImage imageNamed:@"camera_shot"]];
    paiBut.tag = 5;
    [paiBut addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    // 滤镜
    filterBut = [UIButton sj_buttonWithTitle:nil image:[UIImage imageNamed:@"camera_ic_ff_d"] andHighLight:nil selectedImage:[UIImage imageNamed:@"camera_ic_ff_n"]];
    [filterBut addTarget:self action:@selector(rightButAction:) forControlEvents:UIControlEventTouchUpInside];
    filterBut.tag = 6;
    [filterBut setHighlighted:NO];
    
    
    // 设置按钮
    setBut = [UIButton sj_buttonWithTitle:nil image:[UIImage imageNamed:@"camera_ic_adjust_d"] andHighLight:nil selectedImage:[UIImage imageNamed:@"camera_ic_adjust_n"]];
    [setBut addTarget:self action:@selector(rightButAction:) forControlEvents:UIControlEventTouchUpInside];
    filterBut.tag = 7;
    
    
    
    [self addSubview:cameraBut];
    [self addSubview:videoBut];
    [self addSubview:liveBut];
    [self addSubview:palyBut];
    [self addSubview:paiBut];
    [self addSubview:filterBut];
    [self addSubview:setBut];

}
// 添加约束
-(void)addMasConstraint{
    
    
    [videoBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).mas_offset(10);
        make.centerX.equalTo(self);
        make.size.mas_offset(CGSizeMake(40, 40));
        
    }];
    
    [cameraBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).mas_offset(10);
        make.right.equalTo(videoBut.mas_left).mas_offset(-30);
        make.size.mas_offset(CGSizeMake(40, 40));

    }];
    [liveBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).mas_offset(10);
        make.left.equalTo(videoBut.mas_right).mas_offset(30);
        make.size.mas_offset(CGSizeMake(40, 40));
        
    }];
    
    [paiBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(videoBut.mas_bottom).mas_offset(13);
        make.centerX.equalTo(self);
        make.size.mas_offset(CGSizeMake(80, 80));
   
    }];
    
    [palyBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(paiBut.mas_left).mas_offset(-40);
        make.centerY.equalTo(paiBut);
        make.size.mas_offset(CGSizeMake(40, 40));
    }];
    
    [filterBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(paiBut.mas_right).mas_offset(30);
        make.centerY.equalTo(paiBut);
        make.size.mas_offset(CGSizeMake(30, 30));
    }];
    [setBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(filterBut.mas_right).mas_offset(30);
        make.centerY.equalTo(filterBut);
        make.size.mas_offset(CGSizeMake(30, 30));
    }];

}

- (void)buttonAction:(UIButton *)item{
    if (!item.selected) {
        item.selected = YES;
    }
    if (item.tag == 1) {
        videoBut.selected = NO;
        liveBut.selected = NO;
        
        
        
    }else if (item.tag == 2){
        cameraBut.selected = NO;
        liveBut.selected = NO;
    
    
    }else if (item.tag == 3){
        cameraBut.selected = NO;
        videoBut.selected = NO;
       
        
        
        
        
    }else if (item.tag == 4){
        
        
    }else if (item.tag == 5){
        
        
    }
    
    if (liveBut.isSelected) {
        [filterBut setEnabled:YES];
        
        filterBut.selected = YES;
        [setBut setEnabled:YES];
        setBut.selected = YES;
        
        [filterBut setImage:[UIImage imageNamed:@"ic_live_platform_normal"] forState:UIControlStateSelected];
        [setBut setImage:[UIImage imageNamed:@"ic_live_platfrom_setting_normal"] forState:UIControlStateSelected];
    }else{
        [filterBut setImage:[UIImage imageNamed:@"camera_ic_ff_n"] forState:UIControlStateSelected];
        [setBut setImage:[UIImage imageNamed:@"camera_ic_adjust_n"] forState:UIControlStateSelected];
    
    
    }
}

- (void)rightButAction:(UIButton *)item{
    if (item.tag == 6) {
        
    }else if (item.tag == 7){
    
    }
}

- (void)setIsConnection:(BOOL)isConnection{
    if (isConnection) {
        [filterBut setEnabled:YES];
        [setBut setEnabled:YES];
        filterBut.selected = YES;
        setBut.selected = YES;
    }else{
        [filterBut setEnabled:NO];
        [setBut setEnabled:NO];
        filterBut.selected = NO;
        setBut.selected = NO;
    
    }
}



@end
